﻿using Microsoft.AspNetCore.Http;
using NPOI.SS.Formula.Functions;
using NPOI.SS.UserModel;
using Org.BouncyCastle.Asn1.Ocsp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace slwhTools.FileHelper
{
    /// <summary>
    /// 扩展方法类
    /// </summary>
    public static class SFileExtensions
    {
        public static ISFileFactory factory = new SFileHelper();
        public static ISFileConfig sexcel = new SFileConfig();


        /// <summary>
        /// 保存文件流
        /// </summary>
        /// <param name="stream"></param>
        public static async Task<string> SaveFileStreamAsync(this MemoryStream stream, string originalFileName, long fileSize, string filename = "") {
            return   await factory.SaveFileStreamAsync(stream, originalFileName, fileSize, filename);
        }

        /// <summary>
        /// 保存文件流
        /// </summary>
        /// <param name="stream"></param>
        public static string SaveFileStream(this MemoryStream stream, string originalFileName, long fileSize, string filename = "")
        {
            return  factory.SaveFileStream(stream, originalFileName, fileSize, filename);
        }

        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="stream"></param>
        public static string SaveFile(this IFormFile file, string filename = "")
        {
            return factory.SaveFile(file,filename);
        }

        /// <summary>
        /// 保存文件
        /// </summary>
        /// <param name="stream"></param>
        public static async Task<string> SaveFileAsync(this IFormFile file, string filename = "")
        {
            return await factory.SaveFileAsync(file, filename);
        }

        /// <summary>
        /// 保存文件,不进行文件验证
        /// </summary>
        /// <param name="stream"></param>
        public static async Task<string> NoValidSaveFileAsync(this MemoryStream stream, string filename = "")
        {
            return await factory.NoValidSaveFileAsync(stream, filename);
        }
        /// <summary>
        /// 保存文件,不进行文件验证
        /// </summary>
        /// <param name="stream"></param>
        public static string NoValidSaveFile(this MemoryStream stream, string filename = "")
        {
            return  factory.NoValidSaveFile(stream, filename);
        }

        /// <summary>
        /// 下载静态文件
        /// </summary>
        /// <param name="relativePath"></param>
        /// <returns></returns>
        public static async Task<string> ReadStaticFileAsync(string relativePath)
        {
            return await factory.ReadStaticFileAsync(relativePath);
        }

        /// <summary>
        /// 下载本地文件
        /// </summary>
        /// <param name="fullPath"></param>
        /// <returns></returns>
        public static async Task<string> ReadLocalFileAsync(string fullPath)
        {
            return await factory.ReadLocalFileAsync(fullPath);
        }

        /// <summary>
        /// 下载静态文件
        /// </summary>
        /// <param name="relativePath"></param>
        /// <returns></returns>
        public static async Task<byte[]> ReadStaticFileAsBytesAsync(string relativePath)
        {
            return await factory.ReadStaticFileAsBytesAsync(relativePath);
        }


        public static async Task<byte[]> ReadLocalFileAsBytesAsync(string fullPath)
        {
            return await factory.ReadLocalFileAsBytesAsync(fullPath);
        }

        public static async Task<bool> FileExistsAsync(string path)
        {
            return await factory.FileExistsAsync(path);
        }
    }
}


